package com.lance.answer.gui.answer.gk.answer;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.lance.answer.gui.answer.AnswerObject;
import com.lance.answer.gui.answer.DealJsonString;
import com.lance.answer.gui.answer.gk.DealInfoUtil;
import com.lance.answer.gui.answer.gk.answer.task.DoAnswerTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.LinkedBlockingDeque;

/**
 *
 * 校验 每门课程是否完成了............
 */
@Slf4j
public class BatchDoAnswerVaild {

    public static void main(String[] args) throws Exception {

       //   Thread.sleep(1000*60*60*2);
        //     Thread.sleep(7*62*60*1000);
            int sync = 12;

        // String teacher = "刘庆";
        //   String teacher = "李俊杰";
        //   String teacher = "艾";

        List<String> teachers = Lists.newArrayList();
        teachers.add("刘庆");
        teachers.add("李俊杰");
        teachers.add("艾");
        teachers.add("刘");
        // TODO 毛概的都没做
        teachers.add("李明");
        teachers.add("朱晓玉");
        teachers.add("宋柳萌");
        teachers.add("零散");

        Set<String> needAnswerSubject = Sets.newHashSet();



        for (String teacher : teachers) {

            // key = subjectName value 做题链接集合
            Map<String, Set<String>> mapBySubjectName = Maps.newHashMap();
         //   for (File f1 : Objects.requireNonNull(new File("libs//courseUrlInfo").listFiles())) {
            for (File f1 : Objects.requireNonNull(new File("libs//courseUrlInfo//").listFiles())) {
                Set<String> urlTaskSet = Sets.newHashSet();
                if (f1.length() < 50) {
                    continue;
                }
                String fileName = f1.getName();
                String subjectName = fileName.substring(0, fileName.length() - 4);
                List<String> urlInfoList = IOUtils.readLines(new FileInputStream(f1), "utf-8");
                for (String urlInfo : urlInfoList) {
                    if (urlInfo.contains("quiz")) {
                        if (urlInfo.contains("形考")
                                || urlInfo.contains("作业")
                                || urlInfo.contains("考核")
                                || urlInfo.contains("专题测验")
                                || urlInfo.contains("专题检验")
                              //  || urlInfo.contains("测试（")
                                || urlInfo.contains("材料分析题（")
                                || urlInfo.contains("综合记分作业")
                        ) {
                            if(urlInfo.contains("不计入")){
                                continue;
                            }
                            String urlTask = urlInfo.split(",")[0];
                            urlTaskSet.add(urlTask);
                        }
                    }

                }
                mapBySubjectName.put(subjectName, urlTaskSet);
            }



            for (String subjectName : mapBySubjectName.keySet()) {


                List<String> userNames = DealInfoUtil.countUserCourseInfo("libs//userCourseInfo//" + teacher).get(subjectName);

                if (userNames == null) {
                    continue;
                }

                for (String username : userNames) {

                    String filePath = "libs//answerInfo//" +teacher+"//"+ subjectName;
                    //  String filePath = "D:\\project\\answer-tool\\libs\\answerInfo\\" + subjectName;

                    if(!new File(filePath + "//" + username + ".txt").exists()&&!new File(filePath + "//" + username + "-upload.txt").exists()){

                        needAnswerSubject.add(subjectName);
                    }
                }


            }



        }

        for(String name:needAnswerSubject){
            System.out.println("SUBJECT.put(\""+name+"\",\""+name+"\");");
        }




    }


}
